<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta charset="utf-8">
    <title>药品信息管理界面</title>
    <link rel="stylesheet" href="<%=path %>/plugins/layui/css/layui.css" media="all">

  </head>

    <script src="<%=path %>/plugins/layui/layui.js"></script>

<body>
	<!-- 搜索模块 -->
	<div class="demoTable" style="margin-top:7px;margin-left:50px">
	  <div class="layui-inline layui-icon layui-icon layui-icon-search" 
	  style="font-size: 20px; color: #2B2B2B;font-weight:bold">模糊搜索：</div>
	  <div class="layui-inline">
	    <input class="layui-input" name="id" id="demoReload" autocomplete="off">
	  </div>
	  <button class="layui-btn" data-type="reload">搜索</button>
  <sec:authorize ifAnyGranted="medicineAdd">
		  <!-- 小圆点 -->
		  <span style="margin-left: 50px">
			  <span class="layui-badge-dot"></span>
			  <span class="layui-badge-dot layui-bg-orange"></span>
			  <span class="layui-badge-dot layui-bg-green"></span>
			  <span class="layui-badge-dot layui-bg-cyan"></span>
			  <span class="layui-badge-dot layui-bg-blue"></span>
			  <span class="layui-badge-dot layui-bg-black"></span>
			  <span class="layui-badge-dot layui-bg-gray"></span>	
		  </span>	
	  <a href="<%=path%>/biz/Medicine_openAdd.action" 
	  class="layui-icon layui-icon-add-1 layui-btn layui-btn-normal">添加药品</a>
  </sec:authorize>
	</div>
	<!-- 表格体 lay-filter相当于id -->
	<table id="medTable" lay-filter="tableDemo"></table>
</body>

<script>
//调用模块
	layui.use(['table','jquery'], function(){
	  var table = layui.table;
	  var $ = layui.jquery;
	  //定义属性
	  table.render({
	    elem: '#medTable'//关联表格
	    ,url: '<%=path%>/biz/Medicine_getByPager.action' //数据接口
	    ,page: true //开启分页
	    ,cols: [[ //表头
	       {type:'numbers'}
	      ,{type:'checkbox', field: "left"}
	      ,{field: 'medId', title: '编号', align:'center', sort:true}
	      ,{field: 'medName', title: '名称',  align:'center',  sort:true}
	      ,{field: 'medCount', title: '规格',  align:'center',  sort:true}
	      ,{field: 'medSpec', title: '用法',  align:'center',  sort:true}
	      ,{field: 'medFuntion', title: '效果',  align:'center', sort: true} 
	      ,{field: 'medPrice', title: '单价',  align:'center', templet: 
	      '<div class="layui-table-link">{{d.medPrice}}'+"元"+'</div>' ,sort: true}
	      ,{field: 'medTime', title: '有效期',  align:'center', sort: true}
	      ,{field: 'medType', title: '类型', align:'center', sort: true}
	      ,{field: 'operate', title: '操作', width: 200, field: "right", align:'center', toolbar: '#barDemo'}//这里的toolbar值是模板元素的id选择器
	    ]]
	    ,height: 'full-80' //分页块与表格之间的距离
	    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度
	    ,id: 'testReload'
	  });
	  
	  //表格数据重载
	  var $ = layui.$, active = {
	    reload: function(){
	      var demoReload = $('#demoReload');
	      //执行重载
	      table.reload('testReload', {
	        page: {
	          curr: 1 //重新从第 1 页开始
	        }
	        ,where: {
	        	medSpec: demoReload.val(),
	        }
	      });
	    }
	  };
	  $('.demoTable .layui-btn').on('click', function(){
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	  });
	  
	  //监听工具条
	  table.on('tool(tableDemo)', function(obj){
	    var data = obj.data;
	    if(obj.event === 'del'){
	      layer.confirm('真的删除行么', function(index){
	      	$.ajax({
	      		url: '<%=path%>/biz/Medicine_delete.action',
	      		type: 'GET',
	      		data: {"medId":data.medId},
	      		dataType: 'json',
	      		success: function(data){
	      			var json = eval("("+data+")");
	      			if(json.isSucceed){
	      				message("删除成功");
	      				//删除页面记录
	      				obj.del();
	      				
	      			}else{
	      				message("删除失败~不解释");
	      			}
	      		},
	      		error: function(data){
	      			layer.msg("请求失败");
	      		}
	      	});
	      	//关闭弹窗
	        layer.close(index);
	      });
	    } else if(obj.event === 'edit'){
	       //获取挂号编号
	       var medId = data.medId;
	       //iframe窗
			layer.open({
		      type: 2,
		      title: '编辑学生挂号信息',
		      btnAlign: 'c',
		      shadeClose: true,
		      shade: false,
		      maxmin: true, //开启最大化最小化按钮
		      area: ['893px', '600px'],
		      content: '<%=path%>/biz/Medicine_openUpdate.action?medId='+medId
			});

	    }else if(obj.event == "consult"){
	    	message("待开发");
	    	return;
	    }
	  });
	  
	});
	
  //信息提示弹出层
  function message(data){
      layer.open({
        content: '<div style="padding: 20px 100px;">'+ data +'</div>'
        ,btn: '朕知道啦'
        ,btnAlign: 'c' //按钮居中
        ,shade: 0 //不显示遮罩
        ,yes: function(){
          layer.closeAll();
        }
      });
  }
</script>

<script type="text/html" id="barDemo">
<sec:authorize ifAnyGranted="medicineManager,medicineConsult">
  	<a class="layui-btn layui-btn-xs" lay-event="consult">详情</a>
</sec:authorize>
<sec:authorize ifAnyGranted="medicineUpdate">
  	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</sec:authorize>
<sec:authorize ifAnyGranted="medicineDelete">
  	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</sec:authorize>
</script>


</html>
